package bbsimon.first.model.shopcart;

public class BookModel {
	private String _bookName;
	private double _price;
	private String[] _authors;

	public BookModel(String bookName, double price, String[] authors) {
		_bookName = bookName;
		if(_price < 0) {
			_price = 0;
		}
		else {
			_price = price;
		}
		_authors = authors;
	}
	
	public String getBookName() {
		return _bookName;
	}

	public double getPrice() {
		return _price;
	}

	public String[] getAuthors() {
		return _authors;
	}

	public String toString() {
		return _bookName + "|" + _price + "|" + _authors;
	}

	public boolean equals(Object o) {
		BookModel bm = (BookModel)o;
		if(bm.getAuthors().length != _authors.length)
			return false;

		for(int i=0; i < _authors.length; i++) {
			if(!_authors[i].equals(bm.getAuthors()[i])) {
				return false;
			}
		}
		if(!_bookName.equals(bm.getBookName())) {
			return false;
		}
		return true;
	}
}
